<?php

class m_div extends CI_Model{
	
	function _list($data){
		extract($data);
		$sql = "SELECT 
					div_name,
					div_id
				FROM m_div
				WHERE 
					div_active = 'y'
		";
		
		if (@$div_name != "") $sql .= " AND div_name like '%".@$div_name."%'";
		
		$query = $this->db->query($sql);
		$records = $query->num_rows();
		
		$sql = "SELECT * FROM (".$sql.") k LIMIT ".(($page - 1) * $rows).",".$rows;
		$query = $this->db->query($sql);
		$result = $query->result();
		
		return '{ 
		  "total": "'.ceil($records / $rows).'", 
		  "page": "'.$page.'", 
		  "records": "'.$records .'",
		  "rows" : '.json_encode($result).'
		}';
	}
	
	function _insert($data){
		$this->db->insert('m_div',$data);
		return 1;
	}
	
	function _update($data,$id){
		$this->db->where('div_id',$id);
		$this->db->update('m_div',$data);
		return 1;
	}
	
	function _delete($data,$id){
		$this->db->where('div_id',$id);
		$this->db->update('m_div',$data);
		return 1;
	}
}